package com.example.master.service.Impl;

import com.example.master.mapper.UserMapper;
import com.example.master.service.UserService;
import com.example.master.utils.JwtTokenUtil;
import com.example.master.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class UserServiceImpl implements UserService {

    @Autowired
    UserMapper userMapper;

    @Autowired
    JwtTokenUtil jwtTokenUtil;
    @Override
    public Result checkPhone(String phone) {
        String existPhone = userMapper.isExistPhone(phone);
        if (existPhone == null) {
            //注册
            Integer integer = userMapper.addUser(phone);
            if (integer != 1) {
                return Result.error("登录失败");
            }
        }
        return Result.success(jwtTokenUtil.generateToken(phone));
    }


}
